<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/2.png" alt="">
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse? '60px' : '200px'"><!-- 如果是折叠宽度为64 -->
        <div class="toggle-button" @click="toggeCollapse">|||</div>
        <!-- 侧边栏菜单区 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF" unique-opened :collapse="isCollapse"
          :collapse-transition="false" router :default-active="activePath"
          ><!--collapse是否折叠 router开启路由模式点击每一项二级菜单跳转到对应的引用
          default-active当前激活菜单的 index-->
          <!-- 一级菜单 -->
          <el-submenu index="1">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="iconfont icon-users"></i>
              <!-- 文本 -->
              <span>用户管理</span>
            </template>
              <!-- 二级菜单 -->
              <el-menu-item index="users" @click="saveNavState('users')">
                <i class="el-icon-menu"></i>
                <span slot="title">用户列表</span>
              </el-menu-item>    
          </el-submenu>
          <el-submenu index="2">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="iconfont icon-tijikongjian"></i>
              <!-- 文本 -->
              <span>权限管理</span>
            </template>
              <!-- 二级菜单 --> 
              <el-menu-item index="roles" @click="saveNavState('roles')">
                <i class="el-icon-menu"></i>
                <span slot="title">角色列表</span>
              </el-menu-item>
              <el-menu-item index="rights"  @click="saveNavState('rights')">
                <i class="el-icon-menu"></i>
                <span slot="title">权限列表</span>
              </el-menu-item>
                <!-- <el-menu-item index="2-1">角色列表</el-menu-item>
                <el-menu-item index="2-2">权限列表</el-menu-item> -->
          </el-submenu>
          <el-submenu index="3">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="iconfont icon-shangpin"></i>
              <!-- 文本 -->
              <span>商品管理</span>
            </template>
              <!-- 二级菜单 -->
              <el-menu-item index="commodity" @click="saveNavState('commodity')">
                <i class="el-icon-menu"></i>
                <span slot="title">商品列表</span>
              </el-menu-item>
              <el-menu-item index="parameter" @click="saveNavState('parameter')">
                <i class="el-icon-menu"></i>
                <span slot="title">分类参数</span>
              </el-menu-item>
              <el-menu-item index="ification" @click="saveNavState('ification')">
                <i class="el-icon-menu"></i>
                <span slot="title">商品分类</span>
              </el-menu-item>    
          </el-submenu>
          <el-submenu index="4">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="iconfont icon-danju"></i>
              <!-- 文本 -->
              <span>订单管理</span>
            </template>
              <!-- 二级菜单 -->
              <el-menu-item>
              </el-menu-item>     
          </el-submenu>
          <el-submenu index="5">
            <!-- 一级菜单的模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="iconfont icon-baobiao"></i>
              <!-- 文本 -->
              <span>数据统计</span>
            </template>
              <!-- 二级菜单 -->
              <el-menu-item>
              </el-menu-item>     
          </el-submenu>       
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    data(){
      return{
        //是否折叠
        isCollapse:false,
        //被激活的链接地址
        activePath:''
      }
    },
    created(){
      this.activePath=window.sessionStorage.getItem('activePath')
    },
    methods: {
      logout() {
        window.sessionStorage.clear()//清空存储数据
        this.$router.push('/login')//跳转到登录页
      },
      toggeCollapse(){
        //点击按钮切换菜单的折叠与展开
        this.isCollapse=!this.isCollapse
      },
      //保存链接的激活状态
      saveNavState(activePath){
        window.sessionStorage.setItem('activePath',activePath);//键值对
        this.activePath=activePath
      }
    },
  }
</script>
<style lang="less" scoped>
  .home-container{
    height: 100%;
  }
  .el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;
  }
  .el-header>div{
    display: flex;
    align-items: center;
  }
  .el-header>div>span{
    margin-left: 15px;
  }
  .el-aside{
    background-color: #333744;
  }
  .el-menu{
    border-right: none;
  }
  .el-main{
    background-color: #EAEDF1;
  }
  .iconfont{
    padding: 10px;
  }
  .toggle-button{
    background-color: #4A5064;
    font-size: 10PX;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing:0.2em;/*字符间距  em子元素字体大小的em是相对于父元素字体大小*/
    cursor: pointer;/*鼠标变成小手*/
  }
</style>